<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>任务执行情况</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
        $(document).ready(function() {
            $("#btnExport").click(function(){
                top.$.jBox.confirm("确认要导出用户数据吗？","系统提示",function(v,h,f){
                    if(v=="ok"){
                        $("#searchForm").attr("action","${ctx}/sys/user/export");
                        $("#searchForm").submit();
                    }
                },{buttonsFocus:1});
                top.$('.jbox-body .jbox-icon').css('top','55px');
            });
            $("#btnImport").click(function(){
                $.jBox($("#importBox").html(), {title:"导入数据", buttons:{"关闭":true},
                    bottomText:"导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"});
            });
        });
        $(document).ready(function() {

        });

        function exportData() {
			var taskMainId = $("#taskMainId").val();
			window.location.href="${ctx}/devmng/taskMain/exportData?taskMainId=" + taskMainId;
        }

        function page(n,s){
            $("#pageNo").val(n);
            $("#pageSize").val(s);
            $("#searchForm").submit();
            return false;
        }

        function wrapTable(attaVo) {
            if (!attaVo) {
                return "<table><tr><td>没有内容</td></tr></table>";
            }
            var content = "<table style=\"width: 80%\">";
            content += wrapTr4Img(attaVo.title, attaVo.urlList);
            content += "</table>";
            return content;
        }

        function wrapTr4Img(title, urlList) {
            var content = "<tr>"
            content += wrapTd(title);
            content += wrapTd4ImgList(urlList);
            content += "</tr>";
            return content;
        }

        function wrapTd(content) {
            return "<td>" + content + "</td>";
        }

        function wrapTd4ImgList(urlList) {
            if (!urlList || urlList.length == 0) {
                return "<td></td>";
            }
            var content = "<td>";
            for (var i = 0; i < urlList.length; i++) {
                content += wrapImg(urlList[i]);
            }
            content += "</td>";
            return content;
        }

        function wrapImg(url) {
            return "<img width=\"200\" height=\"200\" src=\"" + url + "\" />";
        }

        function showDetail(taskMainId, deviceMainId, devchkItemId) {

            var url = "${ctx}/devmng/taskMain/getTaskDetail";
            var params = {
                taskMainId: taskMainId,
                deviceMainId: deviceMainId,
                devchkItemId: devchkItemId
            };
            $.ajax({
                url: url,
                type: 'post',
                dataType: 'json',
                data: JSON.stringify(params),
                contentType: 'application/json;charset=utf-8',
                success: function(data) {
                    var height = $(window).height()-200;
                    var width = $(document.body).width()-100;
                    var title = "详情";

                    if (!data || !data.taskDetailAttaVo) {
                        $.jBox.open("没有任何内容", title, width, height);
                        return;
                    }
                    var content = wrapTable(data.taskDetailAttaVo);
                    $.jBox.open(content, title, width, height);
                },
                fail: function(err, status) {
                    console.log(err)
                }
            });
        }
	</script>
	<style>
		#bc-open td  {
			color: #ff0100;
		}
	</style>
</head>
<body>
<ul class="nav nav-tabs">
	<li class="active"><a href="#">任务执行情况列表</a></li>
</ul>
<form:form id="searchForm" modelAttribute="taskMainExecDetialRequest" action="${ctx}/devmng/taskMain/taskMainExecDetailCompletedList" method="post" class="breadcrumb form-search">
	<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
	<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
	<input id="taskMainId" name="taskMainId" type="hidden" value="${taskMainId}"/>
	<ul class="ul-form">


		<li class="btns"><a href="javascript: void(0);" class="btn btn-primary" onclick="exportData()">导出</a></li>

		<li class="clearfix"></li>
	</ul>
</form:form>
<sys:message content="${message}"/>
<table id="contentTable" class="table table-striped table-bordered table-condensed">
	<thead>
	<tr>
		<th style="width:60px">任务标题</th>
		<th style="width:60px">任务执行人</th>
		<th style="width:60px">任务类型</th>
		<th style="width:60px">任务状态</th>
		<th style="width:60px">车站值班人员</th>
		<th style="width:60px">跟班人员</th>
		<th style="width:60px">网调室人员</th>
		<th style="width:60px">实际结束时间</th>

		<th style="width:100px">设备名称</th>
		<th style="width:60px">检修周期</th>
		<th style="width:100px">检修内容</th>
		<th style="width:100px">检修标准</th>
		<th style="width:100px">检修方法</th>
		<th style="width:60px">是否正常</th>
		<th style="width:60px">备注</th>
		<th style="width:100px">测量值</th>
		<th style="width:100px">操作</th>
		<%--<shiro:hasPermission name="devmng:taskMain:edit"><th>操作</th></shiro:hasPermission>--%>
	</tr>
	</thead>
	<tbody>
	<c:set var="compare" value=""/>
	<c:set var="count" value="0" />
	<c:forEach items="${page.list}" var="taskMain">
		<c:if test="${taskMain.normalDesc == '不正常'}">
			<c:set var="color"  value="id = bc-open"/>
		</c:if>
		<c:set var="count" value="0" />

		<c:if test="${!compare.equals(taskMain.deviceMainId)}">
			<c:forEach items="${page.list}" var="taskDevchk">
				<c:if test="${taskMain.deviceMainId.equals(taskDevchk.deviceMainId)}">
					<c:set var="count" value="${count+1}"/>
				</c:if>
			</c:forEach>
		</c:if>

		<c:set var="compare" value="${taskMain.deviceMainId}"/>
		<tr <c:out value="${color}"/>>
			<c:if test="${count != 0}">
			<td rowspan="<c:out value="${count}"/>">

			${taskMain.taskTitle}
			</td>
			<td rowspan="<c:out value="${count}"/>">
					${taskMain.taskOperator.name}
			</td>
			<td rowspan="<c:out value="${count}"/>">
					${ fns:getDictLabel (taskMain.taskType, 'DEVCHK_PERIOD', '')}
			</td>
			<td rowspan="<c:out value="${count}"/>">
					${ fns:getDictLabel (taskMain.taskStatus, 'TASK_MAIN_STATUS', '')}
			</td>
			<td rowspan="<c:out value="${count}"/>">
					<%--<fmt:formatDate value="${taskMain.startDate}" pattern="yyyy-MM-dd HH:mm:ss"/>--%>
					${taskMain.stationDutyPerson}
			</td>
			<td rowspan="<c:out value="${count}"/>">
					<%--<fmt:formatDate value="${taskMain.closeDate}" pattern="yyyy-MM-dd HH:mm:ss"/>--%>
					${taskMain.stationAttendant}
			</td>
			<td rowspan="<c:out value="${count}"/>">
					<%--<fmt:formatDate value="${taskMain.taskStart}" pattern="yyyy-MM-dd HH:mm:ss"/>--%>
					${taskMain.netDispatcher}
			</td>
			</c:if>
			<td>
				<fmt:formatDate value="${taskMain.closeDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
			</td>
			<c:if test="${count != 0}">
			<td rowspan="<c:out value="${count}"/>">

			${taskMain.deviceName}
			</td>
			<td rowspan="<c:out value="${count}"/>">

			${ fns:getDictLabel (taskMain.checkPeriod, 'DEVCHK_PERIOD', '')}
			</td>
			</c:if>

			<td>
					${taskMain.checkContent}
			</td>
			<td>
					${taskMain.checkStd}
			</td>
			<td>
					${taskMain.checkMethod}
			</td>
			<td>
					${taskMain.normalDesc}
			</td>
			<td>
					${taskMain.remarks}
			</td>
			<td>
					${taskMain.meatureDesc}
			</td>
			<td>
				<c:choose>
					<c:when test="${taskMain.flagUrl.equals('Y')}">
						<a href="javascript:void(0)"
						   onclick='showDetail("${taskMain.taskMainId}", "${taskMain.deviceMainId}", "${taskMain.devchkItemId}");'>
							查看图片
						</a>
					</c:when>
					<c:otherwise>
						无
					</c:otherwise>
				</c:choose>
			</td>
				<%--<shiro:hasPermission name="devmng:taskMain:edit"><td>--%>
				<%--<a href="${ctx}/devmng/taskMain/detail?id=${taskMain.id}">详情</a>--%>
				<%--<a href="${ctx}/devmng/taskMain/generate?id=${taskMain.id}">修改</a>--%>
				<%--<a href="${ctx}/devmng/taskMain/delete?id=${taskMain.id}" onclick="return confirmx('确认要删除该任务吗？', this.href)">删除</a>--%>
				<%--</td></shiro:hasPermission>--%>
		</tr>
	</c:forEach>
	</tbody>
</table>
<div class="pagination">${page}</div>
</body>
</html>